package com.app.community.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @Author SakuraA6
 * @Description 发送邮件的服务
 * @Date 2020/10/23 21:58
 **/
@Service
public class EmailSendService {
    @Autowired
    JavaMailSender mailSender;

    SimpleMailMessage mailMessage = new SimpleMailMessage();


    public Integer sendRegisterEmail(String messageTo){
        mailMessage.setFrom("852059735@qq.com");
        mailMessage.setTo(messageTo);
        mailMessage.setSubject("欢迎加入湖工社区！");
        Integer verificationCode = (int)((Math.random()*9+1)*100000);
        mailMessage.setText("【湖工社区】欢迎您注册湖工社区，您的验证码为【"+verificationCode+"】请尽快完成验证，不要将验证码告诉别人~");
        // 发送
        mailSender.send(mailMessage);
        return verificationCode;
    }

    public Integer sendResetEmail(String messageTo){
        mailMessage.setFrom("852059735@qq.com");
        mailMessage.setTo(messageTo);
        mailMessage.setSubject("重置您的密码");
        Integer verificationCode = (int)((Math.random()*9+1)*100000);
        mailMessage.setText("【湖工社区】您已成功申请重置密码，您的验证码为【"+verificationCode+"】请尽快完成验证，不要将验证码告诉别人~");
        // 发送
        mailSender.send(mailMessage);
        return verificationCode;
    }
}
